<?php

/**
 * 信息附件关系模型
 */
if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

class Postattachment_model extends MY_Model
{

    public $_table = array(
        'post_attach' => 'post_attach',
    );
    public $_fields = array(
        'post_attach' => array(
            'postid' => 'postid',
            'attachid' => 'attachid',
        ),
    );

    /**
     * 插入数据
     * @param array $data
     * @return int
     */
    public function add( $data )
    {
        $insertData = array(
            'postid' => $data['postid'],
            'attachid' => $data['attachid'],
        );
        $this->db->insert( $this->_table['post_attach'], $insertData );
    }

    public function getByPostId( $postId )
    {
        return $this->db->from($this->_table['post_attach'])
                        ->where('postid', $postId)
                        ->get()
                        ->row_array();
    }

    public function deleteByPostId( $postId )
    {
        $this->db->where('postid', $postId)->delete($this->_table['post_attach']);
    }
    
}

?>
